<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>渠道管理</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
      <style type="text/css">
          html,body{width:100%;}
      </style>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>

	</head>
	<body>
		<div class="easyui-container-fluid">
			<div class="easyui-panel" style="border: none;">
              <div id="nav" class="nav">
                
              </div>
              <div class="easyui-panel">
                   <form id="ff">
                      <div style="margin-bottom:20px;">
                      	<label class="item-label">代码：</label>
                        <input class="easyui-textbox" type="text" name="code"/>
                        <label class="item-label">名称：</label>
                        <input class="easyui-textbox" type="text" name="name"/>
                        <label class="item-label">周上报：</label>
                        <select class="easyui-combobox" name="reportWeekData" data-options="panelHeight:'auto'" style="width:174px;">
                          <option value="">-请选择-</option>
                          <option value="true">是</option>
                          <option value="false">否</option>
                        </select>                     
                        <label class="item-label">月上报：</label>
                        <select class="easyui-combobox" name="reportMonthData" data-options="panelHeight:'auto'" style="width:174px;">
                          <option value="">-请选择-</option>
                          <option value="true">是</option>
                          <option value="false">否</option>
                        </select>
                      </div>
                      <div style="margin-bottom:20px;">
                        <label class="item-label">线上渠道：</label>
                        <select class="easyui-combobox" name="onlineChannel" data-options="panelHeight:'auto'" style="width:174px;">
                          <option value="">-请选择-</option>
                          <option value="true">是</option>
                          <option value="false">否</option>
                        </select>
                        <label class="item-label">退货处理：</label>
                        <select class="easyui-combobox" name="handleRejectSales" data-options="panelHeight:'auto'" style="width:174px;">
                          <option value="">-请选择-</option>
                          <option value="true">是</option>
                          <option value="false">否</option>
                        </select>
                        <label class="item-label">周报处理人：</label>
                        <select id="weekDataOption" class="easyui-combobox" name="weekDataHandleUserId" data-options="panelHeight:'auto'" style="width:174px;">
                        </select>
                        <label class="item-label">月报处理人：</label>
                        <select id="monthDataOption" class="easyui-combobox" name="monthDataHandleUserId" data-options="panelHeight:'auto'" style="width:174px;">
                        </select>
                      </div>
                      <div style="margin-bottom:20px;text-align:center;">
                          <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px;" onclick="searchBy()">查询</a>
                      </div>
                    </form>
                 </div>
                 <div class="table-wrapper">
                   <table id="datagrid" class="easyui-datagrid">
                     <thead>
                       <tr>
                         <th data-options="field:'code',align:'center'" width="80">代码</th>
                         <th data-options="field:'name',align:'center'" width="80">名称</th>
                         <th data-options="field:'remark',align:'center'" width="120">备注</th>
                         <th data-options="field:'reportWeekData',align:'center',formatter:boolFormatter" width="80">周上报</th>
                         <th data-options="field:'reportMonthData',align:'center',formatter:boolFormatter" width="80">月上报</th>
                         <th data-options="field:'onlineChannel',align:'center',formatter:boolFormatter" width="80">线上渠道</th>  
                         <th data-options="field:'handleRejectSales',align:'center',formatter:boolFormatter" width="80">退货</th>
                         <th data-options="field:'weekDataHandleUserId',align:'center'" width="80">周报处理人</th>
                         <th data-options="field:'monthDataHandleUserId',align:'center'" width="80">月报处理人</th>
                         <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>
                         <th data-options="field:'updateTime',align:'center'" width="160">添加时间</th>
                         <th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th>
                       </tr>
                     </thead>
                     <tbody>
                     </tbody>
                   </table>
                 </div>
            </div> 
         </div>
	</body>
  <script type="text/javascript">

    $(function(){
           //console.log
           setNav();
           $("#datagrid").datagrid({
               pagination:true,
               rownumbers:true,
               toolbar:[{
                    text:'添加渠道',
                    //iconCls:'icon-add',
                    handler:function(){
                      window.parent.addTab("添加渠道","../channel/config/add.html");
                    }
                }]
           });
           $.ajax({
               url:config.url + "/channels/getChannelPage",
               type:"get",
               xhrFields:{withCredentials:true},
               success:function(data){
                  $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                    pageList:[10,15,20,25,30,35,40,50,100],
                    displayMsg:"共"+data.totalElements+"条记录"
                  });
               },
               error:function(data){
                  console.log(data);
               }
           });
           $("#weekDataOption").combobox({
                url:config.url+"/user/queryall",
                method:'get',
                valueField:"id",
                textField:"username"
           });
           $("#monthDataOption").combobox({
                url:config.url+"/user/queryall",
                method:'get',
                valueField:"id",
                textField:"username"
           });
      });
     function actions(val,row,index){
         return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
         "onclick='edit(\""+row.id+"\")'>修改</a>&nbsp;&nbsp;"+
         "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
         "onclick='disableOne(\""+row.id+"\")'>禁用</a>";
     }
     function edit(id){
          window.location.href = "./add.html?id="+id;
     }
     function disableOne(data){
          $.messager.confirm("提示","您确定禁用该记录吗？",function(flag){
               if(flag){
                  $.ajax({
                      url:config.url+"/channels?id="+data,
                      type:'DELETE',
                      xhrFields:{withCredentials:true},
                      success:function(data){
                          $.messager.alert("提示","操作成功");
                          $.ajax({
                             url:config.url + "/channels/getChannelPage",
                             type:"get",
                             xhrFields:{withCredentials:true},
                             success:function(data){
                                $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                                  pageList:[10,15,20,25,30,35,40,50,100],
                                  displayMsg:"共"+data.totalElements+"条记录"
                                });
                             },
                             error:function(data){
                                console.log(data);
                             }
                         });
                      },
                      error(XMLHttpRequest,textStatus,thrown){

                      }
                  });
               }
          });
     }

     function searchBy(){
        var data = getFormData(document.getElementById("ff"));
        $.ajax({
             url:config.url + "/channels/getChannelPage",
             type:"get",
             data:transfer(data),
             xhrFields:{withCredentials:true},
             success:function(data){
                $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                  pageList:[10,15,20,25,30,35,40,50,100],
                  displayMsg:"共"+data.totalElements+"条记录"
                });
             },
             error:function(data){
                console.log(data);
             }
         });
     }
  </script>
</html>